namespace ClassyBlog.Web
{
    using System;

    public static class Pagination
    {
        public static int StartIndex(int? pageNo, int pageSize)
        {
            return (pageNo.HasValue && (pageNo.Value > 1)) ?
                   ((pageNo.Value - 1) * pageSize) :
                   0;
        }

        public static int PageCount(int total, int pageSize)
        {
            if ((total == 0) || (pageSize == 0))
            {
                return 1;
            }

            if ((total % pageSize) == 0)
            {
                return total / pageSize;
            }

            var result = Convert.ToDouble(total / pageSize);

            result = Math.Ceiling(result);

            return Convert.ToInt32(result) + 1;
        }
    }
}